﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.Linq;
using System.Xml.Linq;

namespace CF.Web.Ext.Net
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                XElement document = XElement.Load(Server.MapPath("resources/DashboardSchema.xml"));
                var defaultIcon = document.Attribute("defaultIcon") != null ? document.Attribute("defaultIcon").Value : "";

                var query = from g in document.Descendants("group")
                            select new
                            {
                                Title = g.Attribute("title") != null ? g.Attribute("title").Value : "",
                                Items = (from i in g.Elements("item")
                                         select new
                                         {
                                             Title = i.Element("title") != null ? i.Element("title").Value : "",
                                             Icon = i.Element("item-icon") != null ? i.Element("item-icon").Value : defaultIcon,
                                             Id = i.Element("id") != null ? i.Element("id").Value : ""
                                         }
                                    )
                            };

                this.Store1.DataSource = query;
                this.Store1.DataBind();

            }
        }
    }
}